<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>??空值合并运算符</title>
</head>

<body>
    <script>
        console.log('----------------- || -------------------')
        // 在 || 运算符下， null、undefined、0、false、空字符串'' 都会取右侧数据
        const a = null || 'null的'
        const b = undefined || 'undefined的'
        const c = 0 || '0的'
        const d = false || 'fale的'
        const e = '' || '""的'
        console.log('a ====> ', a)
        console.log('b ====> ', b)
        console.log('c ====> ', c)
        console.log('d ====> ', d)
        console.log('e ====> ', e)
        console.log('----------------- ?? -------------------')
        // 在 ?? 运算符下，左侧操作数（变量或表达式）的值为 null 或 undefined 时返回右侧操作数
        const aa = null ?? 'null ??'
        const bb = undefined ?? 'undefined ??'
        const cc = 0 ?? '0 ??'
        const dd = false ?? 'false ??'
        const ee = '' ?? '空字符串 ??'
        console.log('aa ====> ', aa)
        console.log('bb ====> ', bb)
        console.log('cc ====> ', cc)
        console.log('dd ====> ', dd)
        console.log('ee ====> ', ee)
    </script>
</body>

</html>